Cartesian Products

A Cartesian Product occurs when Oracle joins all of the rows in one table to all of the rows in another table. If the number of rows in one of those tables is zero or one, this will not be a problem. However consider the consequences if both tables have more than 100,000 rows.100,000 x 100,000 = 100,000,000,000. ie. 100 billion rows. Clearly this will not run fast.

To find out whether your SQL is performing a Cartesian Product, run it through Explain Plan and search for a step that looks like this:

There are several situations where Oracle will use a Cartesian Product

If you have appropriate join predicates, up to date statistics, no hints, and tables selecting 0 or 1 row, then Oracle should not be performing a Cartesian Product. If it is still happending, look at your join prediactes and consider the best order to join the tables. Place the tables in the FROM clause in that order and add the ORDERED hint to the SQL. This should stop the cartesian product. If it is still slow, continue reading this Guide for other alternatives.


©Copyright 2003